// components/custom-nav-bar/index.js
Component({
    /**
     * 组件的属性列表
     */
    properties: {

    },

    /**
     * 组件的初始数据
     */
    data: {
        // 状态栏高度
        statusBarHeight: wx.getStorageSync('statusBarHeight') + 'px',
        // 导航栏高度
        navigationBarHeight: wx.getStorageSync('navigationBarHeight') + 'px',
        // 胶囊按钮高度
        menuButtonHeight: wx.getStorageSync('menuButtonHeight') + 'px',
        // 导航栏和状态栏高度
        navigationBarAndStatusBarHeight: wx.getStorageSync('statusBarHeight') +
            wx.getStorageSync('navigationBarHeight') + 'px',
        userInfo: {}
    },

    lifetimes: {
        attached: function () {
            const logged = wx.getStorageSync('logged')
            if (logged) {
                this.setData({
                    userInfo: wx.getStorageSync('userInfo')
                })
            }
        },
    },

    /**
     * 组件的方法列表
     */
    methods: {
        toSearch() {
            wx.navigateTo({
                url: '../../pages/search-view/index?param=0',
            })
        },
        toLogin() {
            if (!wx.getStorageSync('logged')) {
                wx.navigateTo({
                    url: '../../pages/login/index',
                })
            }else {
                wx.switchTab({
                  url: '/pages/me/index',
                })
            }
        }
    }
})